angular.module('starter.controllers')
.controller('QrcodeCtrl', function($scope, museumFac, $stateParams, $timeout, $location, $cookies) {
	$scope.height1 = $(window).height();

	$scope.change_language = function(id){
	    $scope.language = id;
	    var expireDate = new Date();  
	    expireDate.setDate(expireDate.getDate() + 30);                
	    $cookies.put('language', id, {'expires': expireDate.toUTCString()});
	    location.reload();
	    if(id == 0){
	      document.getElementById('title').innerHTML = '提示';
	      document.getElementById('windowclosebutton').value = '确定';
	    }else{
	      document.getElementById('title').innerHTML = 'Hint';
	      document.getElementById('windowclosebutton').value = 'Confirm';
	    }

	}

	$scope.getLanguage = function(){
    	$scope.language = $cookies.get('language');
    	if($scope.language){
        	$scope.language = $scope.language;
    	}else{
        	$scope.language = 0;
    	}
    	if($scope.language == 0){
	      document.getElementById('title').innerHTML = '提示';
	      document.getElementById('windowclosebutton').value = '确定';
	    }else{
	      document.getElementById('title').innerHTML = 'Hint';
	      document.getElementById('windowclosebutton').value = 'Confirm';
	    }
  	}
  	$scope.getLanguage();

	$scope.getUser = function() {
	  museumFac.user.profile(function(data){
	    $scope.user = data.info;

	    var qrcode = new QRCode(document.getElementById("qrcode"), {
	      width : 260,
	      height : 260
	    });

	    if($scope.user.vipcode){
	    	qrcode.makeCode($scope.user.vipcode);
	    }else{
	    	qrcode.makeCode($scope.user.id);
	    }
	    
	  },function(data){
	    alert(data.data.info);
	  });
	};
    $scope.getUser();

  
})